#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author: xjx
@time: 2023/11/9 10:26 
@file: data_to_dataframe.py
@project: nanchangproject
@describe: 数据库数据转化为dataframe
"""
import os
import sys
import django
from django_pandas.io import read_frame

sys.path.append('../../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nanchangproject.settings')
django.setup()  # 很关键的配置，必须先setup在导入models类
from drivinginfo.models import Drivinginfo


def data_to_dataframe(vin: str):
    """
    @param vin: 根据VIN码筛选数据
    @return: pandas.dataframe
    """
    qs = Drivinginfo.objects.filter(vin=vin)
    qs_dataframe = read_frame(qs=qs)
    print(f'车辆{vin}数据库数据已转化为dataframe')
    # print(qs_dataframe)
    return qs_dataframe


if __name__ == '__main__':
    qs = Drivinginfo.objects.filter(vin='LETYBEG23MH043111')
    qs_dataframe = read_frame(qs=qs)
    x = qs_dataframe.loc[1533, ['car_speed']].values  # numpy.ndarray
    y=qs_dataframe.car_speed
    print(y)
    # 数据库中的0变换为0.000
